package cn.ecnu.auction.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import org.apache.log4j.Logger;

import ToolPackage.Json;

import cn.ecnu.auction.db.DbConnection;
import cn.ecnu.auction.po.Goods;

public class GoodsDAO {
	private static Logger logger = Logger.getLogger(GoodsDAO.class);
	
	/**
	 * 新增拍卖品
	 * @param gname 拍卖品名称
	 * @param description 描述
	 * @param startPrice 起拍价
	 * @param lastingTime 拍卖时间
	 * @param uid 拍卖品提供者
	 * @result result >= 0 正确  result = -1 错误
	 */
	public int addGood(String gname, String description, double startPrice, double startTime, double lastingTime){
		Connection conn = DbConnection.getConnection();
		String sql = "insert into goods(gid, gname, description, startPrice, startTime, lastingTime) values(null, ?, ?, ?, ?, ?)";
		int result = 0;
		try {
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, gname);
			pstmt.setString(2, description);
			pstmt.setDouble(3, startPrice);
			pstmt.setDouble(4, startTime );
			pstmt.setDouble(5, lastingTime);
			logger.info(pstmt);
			result = pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
			result = -1;
		} finally {
			DbConnection.closeConnection(conn);
		}
		return result;
	}
	
	
}
